var express = require('express');
var router = express.Router();

var mongoose = require('mongoose');
var User = require('./../models/users.js');
mongoose.connect('mongodb://127.0.0.1:27017/first',{useNewUrlParser:true});


mongoose.connection.on("disconnected",function(){
	console.log("MongoDB is fail")
});

//连接上数据库
mongoose.connection.on("connected",function(){
	console.log("MongoDB is success")
});

//出现错误
mongoose.connection.on("error",function(){
	console.log("MongoDB is error")
});

router.post("/getName",function(req,res,next){
	let userId = req.body.userId;
	
	User.findOne({userId:userId},function(err,doc){
		if(err){
			res.json({status:'1',msg:'没有这个用户',result:''})
		}else{
			res.json({status:'0',msg:'',result:{userName:doc.userName}})
		}
	});
});
module.exports = router;
